package com.api.shopapi.mapper;

import com.api.shopapi.entity.CashierCartGoods;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CashierCartGoodsMapper {

    @Insert("insert into cashier_cart_goods" +
            "(" +
            "CashierCartGoodsCode," +
            "CashierCartBusinessCode," +
            "GoodsCode," +
            "Number," +
            "CreateTime," +
            "AddedType" +
            ")" +
            "values" +
            "(" +
            "#{cashierCartGoods.CashierCartGoodsCode}," +
            "#{cashierCartGoods.CashierCartBusinessCode}," +
            "#{cashierCartGoods.GoodsCode}," +
            "#{cashierCartGoods.Number}," +
            "#{cashierCartGoods.CreateTime}," +
            "#{cashierCartGoods.AddedType}" +
            ")")
    public int insert(@Param("cashierCartGoods") CashierCartGoods cashierCartGoods);

    @Update("update cashier_cart_goods set " +
            "CashierCartBusinessCode = #{cashierCartGoods.CashierCartBusinessCode}," +
            "GoodsCode=#{cashierCartGoods.GoodsCode}," +
            "Number=#{cashierCartGoods.Number}," +
            "CreateTime=#{cashierCartGoods.CreateTime}," +
            "AddedType=#{cashierCartGoods.AddedType}" +
            " where CashierCartGoodsCode=#{cashierCartGoods.CashierCartGoodsCode}")
    public int update(@Param("cashierCartGoods") CashierCartGoods cashierCartGoods);

    @Delete("delete from cashier_cart_goods where CashierCartGoodsCode=#{cashierCartGoodsCode}")
    public int delete(@Param("cashierCartGoodsCode") String cashierCartGoodsCode);

    @Select("select * from cashier_cart_goods order by CreateTime desc")
    public List<CashierCartGoods> getList();

    @Select("select * from cashier_cart_goods where CashierCartGoodsCode=#{cashierCartGoodsCode} limit 1")
    public CashierCartGoods getByCashierCartGoodsCode(@Param("cashierCartGoodsCode") String cashierCartGoodsCode);


    @Select("select * from cashier_cart_goods where CashierCartBusinessCode=#{cashierCartBusinessCode}")
    public List<CashierCartGoods> getListByCashierCartBusinessCode(@Param("cashierCartBusinessCode") String cashierCartBusinessCode);

    @Select("select * from cashier_cart_goods where GoodsCode=#{goodsCode}")
    List<CashierCartGoods> getListByGoodsCode(@Param("goodsCode")String goodsCode);


}
